package thread;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 刘远望
 * Date: 2025-05-21
 * Time: 17:02
 */
public class Demo8 {
    public static void main(String[] args) throws InterruptedException {
        /**
         * isAlive方法式判断线程是否还活着
         */
        Thread thread = new Thread(() -> {
            for (int i = 0; i < 3; i++) {
                System.out.println("hello thread");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            System.out.println("线程结束");
        });

        //这个结果一定式false
        //此时进程还没开始，还没调用start
        System.out.println(thread.isAlive());
        thread.start();

        while (true) {
            System.out.println(thread.isAlive());
            Thread.sleep(1000);
        }
    }
}
